package cn.ljn.basic.service.impl;

import cn.ljn.basic.mapper.BaseMapper;
import cn.ljn.basic.query.BaseQuery;
import cn.ljn.basic.service.BaseService;
import cn.ljn.basic.util.PageList;
import cn.ljn.org.mapper.DepartmentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements BaseService<T> {
    @Autowired
    private BaseMapper<T> mapper;


    @Override
    public List<T> findAll() {
        return mapper.findAll();
    }

    @Override
    public T findById(Long id) {
        return mapper.findById(id);
    }

    @Override
    public void add(T T) {
        mapper.add(T);
    }

    @Override
    public void update(T T) {
        mapper.update(T);
    }

    @Override
    public void delete(Long id) {
        mapper.delete(id);
    }

    @Override
    public PageList<T> queryByPage(BaseQuery query) {
        Integer totals = mapper.queryByCount(query);
        if (0 >= totals){
            return new PageList<>(totals,new ArrayList<>());
        }
        List<T> rows = mapper.queryByPage(query);
        return new PageList<>(totals,rows);
    }

    @Override
    public void batchDelete(List<Long> ids) {
        mapper.batchDelete(ids);
    }
}
